﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SerialPortExp
{
    public partial class FrmQuickCommand : Form
    {
        //保存信息的属性
        public string CommandName { get; set; }

        public string CommandContent { get; set; }


        public FrmQuickCommand()
        {
            InitializeComponent();
        }


        //获取旧值（或者说是已经保存了的值）
        public FrmQuickCommand(string cmdName, string cmdContent)
        {
            InitializeComponent();

            //赋值
            CommandName = cmdName;
            CommandContent = cmdContent;
        }

        //确认
        private void btnOk_Click(object sender, EventArgs e)
        {
            string str = this.txtCommand.Text.Trim().Replace(" ", "");

            //判断是否为十六进制数,并且长度不为奇数(看具体协议要求)
            if (Transform.IsHexString(str) && str.Length % 2 == 0)
            {
                //更新数据
                CommandName = this.txtCommandName.Text;
                CommandContent = this.txtCommand.Text;

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("格式不正确！","格式错误提示");
                return;
            }
        }

        //取消
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
